<?php
namespace Admin\Models\user;

use Phalcon\Mvc\Model;
use Helpers\Tool;

class UserOnline extends Model
{

    /**
     *
     * @var integer
     */
    public $userId;

    /**
     *
     * @var string
     */
    public $logonName;

    /**
     *
     * @var string
     */
    public $userName;

    /**
     *
     * @var string
     */
    public $pageTitle;

    /**
     *
     * @var string
     */
    public $pageUrl;

    /**
     *
     * @var string
     */
    public $ip;

    /**
     *
     * @var string
     */
    public $os;

    /**
     *
     * @var string
     */
    public $browser;

    /**
     *
     * @var integer
     */
    public $updateTime;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHSys_UserOnline';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return UserOnline[]|UserOnline|\Phalcon\Mvc\Model\ResultSetInterface
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return UserOnline|\Phalcon\Mvc\Model\ResultInterface
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    public function beforeSave()
    {
        $this->updateTime = time();
        $this->ip = Tool::getIp();
        $this->os = Tool::getOS();
        $this->browser = Tool::getBrowser();
        return true;
    }

}
